package My_Workers;

import org.jboss.aop.advice.annotation.JoinPoint;
import org.jboss.aop.advice.annotation.Target;
import org.jboss.aop.joinpoint.ConstructorInvocation;
import org.jboss.aop.joinpoint.FieldAccess;

public class LoggingAspect {

	public void logBefore(@JoinPoint FieldAccess fieldAccess, @Target Workers worker)
	   {
	      System.out.println("F: Field name " + fieldAccess.getField().getName() + " for worker " + worker.getName());
	      System.out.println("F: Field salary " + worker.getSalary());
	   }

	   public void logAfter(@Target Workers worker)
	   {
	      System.out.println("After");
	   }
	   
	   public Object log(ConstructorInvocation invocation) throws Throwable
	   {
	      try
	      {
	    	  System.out.println("F: Worker with constructor: " + invocation.getConstructor());
	    	  System.out.println("C: Worker number: " + invocation.getArguments()[0]);
	         return invocation.invokeNext();
	      }
	      finally
	      {
	         System.out.println("C: Done");
	      }
	   }
}
